package com.example.workbook.controller;

import com.example.workbook.common.R;
import com.example.workbook.model.request.UserRequest;
import com.example.workbook.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 注册用户
     * @param registryRequest
     * @return
     */
    @PostMapping("/registryUser")
    public R registryUser(@RequestBody UserRequest registryRequest) {
        return userService.registryUser(registryRequest);
    }

    /**
     * 用户登录
     * @param loginRequest
     * @param httpSession
     * @return
     */
    @PostMapping("/userlogin")
    public R userLogin(@RequestBody UserRequest loginRequest, HttpSession httpSession) {
        return userService.userLogin(loginRequest,httpSession);
    }
    /**
     * 返回所有用户
     * @return
     */
    @GetMapping("/allUser")
    public R allUser() {
        return userService.allUser();
    }

    /**
     * 返回指定ID的用户
     * @param id
     * @return
     */
    @GetMapping("/userdetail")
    public R userOfId(@RequestParam int id) {
        return userService.userOfId(id);
    }


}
